<template>
	<view>
		<custom :title="info.title" mode="2" fixed="fixed"></custom>

		<!-- icon-jinru -->
		<view class="mt-20 pl-31" style="background-color: #FFFFFF;">
			<view class="setting-item flex flex-x-b flex-y-center">
				<input @confirm="edit_name" confirm-type="done" type="text" v-model="value"
					style="height: 100rpx;font-size: 34rpx;flex:1;">
				<view @tap.stop="clear_name" class="iconfont icon-guanbi-  fs-40 ml-30" style="color: #D8D8D8;"></view>
			</view>

		</view>

		<view @tap="edit_name" hover-class="click" hover-start-time="2"
			class="flex flex-x-y bg-all"
			style="width: 672rpx;height: 88rpx;border-radius: 44rpx;color: #fff;font-size: 36rpx;margin:52rpx auto 0 auto;">
			确定修改
		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: '',
				title:'设置名称',
				infos:[
					{
						title: '设置名称',
						key: 'name',
						name: '名字'
					},{
						title: '设置签名',
						key: 'signature',
						name: '签名'
					}
				],
				type: 0
			}
		},
		onLoad(option) {
			this.type = +option.type
		},
		computed: {
			info() {
				return this.infos[this.type]
			}
		},
		mounted() {
			this.value = this.user_info[this.info.key];
		},
		methods: {
			clear_name() {
				this.value = '';
			},
			edit_name() {
				let value = this.value.trim();
				if (value.length == 0 || value.length > 12) {
					this.showToast( this.info.name + '长度在1-12之间');
					return;
				}
				this.request({
						url: '/user/update',
						loading: true,
						data: {
							[this.info.key]: value
						},
						method: 'POST',
						loading: true,
					}).then(res => {
						if (res.status == 200) {
							this.showToast('修改成功');
							this.$store.dispatch('refresh_user');
							setTimeout(() => {
								this.uniBack();
							}, 500);
						}
					});

			},
		}
	}
</script>

<style>
	page {
		background-color: #EFF0F1;
	}

	.setting-item {
		height: 142rpx;
		background-color: #FFFFFF;
		padding-right: 30rpx;

	}

	/* .setting-item+.setting-item {
		border-top: 0.5px solid #D8D8D8;
	} */
</style>

